<template>
  <div class="con">
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <!-- :to="{ path: '/' }" -->
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/home/document' }">文档</el-breadcrumb-item>
        <el-breadcrumb-item class="dangqian">文档详情</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="main">
        <div class="left">
          <el-tree :data="types"
                   :props="defaultProps"
                   accordion
                   :default-expanded-keys="[id]"
                   :current-node-key="id"
                   :highlight-current="true"
                   node-key="id"
                   @node-click="handleNodeClick">
          </el-tree>
        </div>
        <div class="right">
          <div class="title">{{detail.name}}</div>
          <div class="time">更新时间：{{detail.caAt}}</div>
          <div class="cont"
               v-html="detail.content"></div>
          <div class="btns">
            <div class="btnbox"
                 @click="look">
              <img src="@/assets/img/xiazai.png">
              <span>查看文件</span>
            </div>
            <div class="btnbox"
                 v-clipboard:copy="message"
                 v-clipboard:success="share">
              <img src="@/assets/img/femxiang.png">
              <span>分享</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: '',
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      detail: {},
      types: [],
      id: '',
      message: ''
    }
  },
  //注册组件
  components: {},
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.isinput();
    this.gettypes()
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      this.getdetail()
    }
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() { },
  //计算属性
  computed: {},
  //方法
  methods: {
    gettypes() {
      this.$postRequest('/api/trotocol/getTrotocolClassList', {
        status: 1
      }).then(res => {
        this.types = res.data
      })
    },
    getdetail() {
      this.$postRequest('/api/trotocol/getTrotocolInfoByClassId', {
        id: this.id
      }).then(res => {
        this.message = window.location.href
        this.detail = res.data
      })
    },
    look() {
      // console.log('aaaa')
      if (this.detail && this.detail.fileUrl) {
        window.location.href = this.detail.fileUrl
      } else {
        this.$message({
          message: "该文档暂无文件",
          type: "warning",
        });
      }
    },
    share() {
      this.$message.success('复制成功')
    },
    handleNodeClick(data) {
      // console.log(data)
      if (!data.children && data.id != this.id) {
        this.$router.push({ name: 'documentitem', query: { id: data.id } })
        this.id = data.id
        this.getdetail()
      }
    },
    isinput() {
      this.$store.commit('setDValue', false)
    },
  }
}
</script>
<style scoped lang="scss">
.con {
  background-color: #f9f9f9;
  & > div {
    width: 1400px;
    margin: auto;
    /deep/ .el-breadcrumb {
      height: 48px;
      font-size: 14px;
      line-height: 48px;
      .el-breadcrumb__inner {
        color: #999;
        font-weight: 500;
      }
      .dangqian .el-breadcrumb__inner {
        color: #1a69e0;
      }
    }
    .main {
      width: 100%;
      display: flex;
      justify-content: space-between;
      /deep/ .el-tree-node__label {
        font-size: 16px;
      }
      /deep/ .el-tree-node__content {
        height: 40px;
      }
      .left {
        width: 250px;
        padding: 30px 0 30px 20px;
        background: #fff;
        border: 1px solid #eeeeee;
        min-height: 500px;
      }
      .right {
        min-height: 500px;
        flex: 1;
        background: #fff;
        padding: 30px;
        position: relative;
        border: 1px solid #eeeeee;
        border-left: none;
        .title {
          font-size: 24px;
          font-weight: bold;
          margin: 10px 0 20px 0;
        }
        .time {
          font-size: 14px;
          color: #999;
          margin-bottom: 40px;
        }
        .btns {
          position: absolute;
          right: 30px;
          top: 40px;
          display: flex;
          align-items: center;
          .btnbox {
            display: flex;
            align-items: center;
            margin-left: 30px;
            cursor: pointer;
            img {
              height: 27px;
              width: 27px;
              margin-right: 10px;
            }
            span {
              color: #999;
              font-size: 14px;
            }
          }
        }
      }
    }
  }
}
</style>